package br.com.felix.commandline;

import br.com.felix.util.ILogDevice;

/**
 * ILogDevice implementation that logs in the memory for further reading.
 * @see ILogDevice
 * */
public class MemoryLog implements ILogDevice{

	private boolean errorHasOcurred = false;
	private StringBuffer strb = new StringBuffer();

	/**
	 * Stores log in the memory.
	 * */
	public void log(String str) {
		strb.append(str).append("\n");
	}
	
	/**
	 * Stores error log in the memory.
	 * */
	public void error(String msg, Exception e) {
		log(msg+"; "+e.getMessage());
	}
	
	
	/**
	 * Returns all the messages logged.
	 * */
	public String toString(){
		return strb.toString();
	}

	@Override
	public boolean errorHasOcurred() {
		return errorHasOcurred;
	}

	@Override
	public void lookForErrorsAgain() {
		errorHasOcurred = false;
	}

	
}
